package com.service;/**
 * @AUTHOR: 我是章璐锋憨憨
 * @Data:
 * @Version:
 */

import com.dao.ProviderDao;
import com.pojo.Provider;

import java.util.List;
import java.util.Objects;

/**
 * @outhor RD
 * 2021/12/24
 */
public class ProviderService {
    private ProviderDao dao = new ProviderDao();

    public List<Provider> getProviders() {
        return dao.queryAll();
    }

    public List<Provider> getProviders(Integer currentPageNo,Integer pageSize) {
        return dao.queryLimit(currentPageNo,pageSize);
    }

    public boolean save(Provider provider) {
        return dao.addOne(provider);
    }

    public Provider get(Integer id) {
        List<Provider> pros = dao.queryById(id);
        if (Objects.nonNull(pros) && pros.size() > 0) {
            return pros.get(0);
        }
        return null;
    }

    public void remove(Integer id) {
        dao.deleteById(id);
    }

    public boolean modify(Integer id, Provider pro) {
        return dao.update(id, pro);
    }

    public List<Provider> search(String proCode, String proName) {
        if (Objects.equals(proCode, "")) {
            return dao.queryLikeName(proName);
        } else if (Objects.equals(proName, "")) {
            return dao.queryLikeCode(proCode);
        } else {
            return dao.queryLike(proCode, proName);
        }
    }
}
